package com.hz.ruoyiquality.service.impl;



import com.hz.ruoyiquality.domain.LgQuality;
import com.hz.ruoyiquality.mapper.LgQualityMapper;
import com.hz.ruoyiquality.service.LgQualityService;
import com.ruoyi.common.core.constant.UserConstants;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import java.util.List;

/**
 * @Author: bjb
 * @CreateTime: 2025-03-05
 */

@Service
public class LgQualityServiceImpl implements LgQualityService {
    @Autowired
    private LgQualityMapper lgQualityMapper;

    /**
     * 登录
     *
     * @param account
     * @param password
     * @return
     */
    @Override
    public LgQuality login(String account, String password) {
        LgQuality quality = lgQualityMapper.selectByAccount(account);
        if (quality != null) {
            // 直接比对明文密码
            if (quality.getPassword().equals(password)) {
                return quality;
            }
        }
        return null;
    }

    /**
     * 查询质检员信息集合
     *
     * @param lgQuality 质检员信息
     * @return 质检员信息集合
     */
    @Override
    public List<LgQuality> selectLgQualityList(LgQuality lgQuality)
    {

        return lgQualityMapper.selectLgQualityList(lgQuality);
    }



    /**
     * 新增保存质检员信息
     *
     * @param lgQuality 质检员信息
     * @return 结果
     */
    @Override
    public int insertLgQuality(LgQuality lgQuality) {
        return lgQualityMapper.insertLgQuality(lgQuality);
    }
    /**
     * 校验质检员名称是否唯一
     *    account
     * @param lgQuality 质检员信息
     * @return 结果
     */
    @Override
    public boolean checkLgQualityNameUnique(LgQuality lgQuality) {
        Long lgQualityId = StringUtils.isNull(lgQuality.getId()) ? -1L : lgQuality.getId();
        LgQuality info = lgQualityMapper.checkLgQualityNameUnique(lgQuality.getAccount());
        if (StringUtils.isNotNull(info) && info.getId().longValue() != lgQualityId.longValue())
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }
    /**
     * 校验质检员编码是否唯一
     *  username
     * @param lgQuality 质检员信息
     * @return 结果
     */
    @Override
    public boolean checkLgQualityCodeUnique(LgQuality lgQuality) {
        Long lgQualityId = StringUtils.isNull(lgQuality.getId()) ? -1L : lgQuality.getId();
        LgQuality info = lgQualityMapper.checkLgQualityCodeUnique(lgQuality.getUsername());
        if (StringUtils.isNotNull(info) && info.getId().longValue() != lgQualityId.longValue())
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    /**
     * 通过岗位ID查询岗位信息
     *
     * @param id 岗位ID
     * @return 角色对象信息
     */
    @Override
    public LgQuality selectLgQualityById(Integer id)
    {
        return lgQualityMapper.selectLgQualityById(id);

    }


    /**
     * 修改保存岗位信息
     *
     * @param post 岗位信息
     * @return 结果
     */
    @Override
    public int updateLgQuality(LgQuality post)
    {
        return lgQualityMapper.updateLgQuality(post);
    }

    /**
     * 查询所有质检员,可以全查也可以进行导出数据
     *
     * @return 质检员列表
     */
    @Override
    public List<LgQuality> selectLgQualityAll()
    {
        return lgQualityMapper.selectLgQualityAll();
    }

    /**
     * 删除岗位信息
     *
     * @param id 岗位ID
     * @return 结果
     */
    @Override
    public int deleteLgQualityById(Integer id)
    {
        return lgQualityMapper.deleteLgQualityById(id);
    }

    /**
     * 批量删除岗位信息
     *
     * @param ids 需要删除的岗位ID
     * @return 结果
     */
    @Override
    public int deleteLgQualityByIds(Integer[] ids)
    {
        return lgQualityMapper.deleteLgQualityByIds(ids);
    }


}
